
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <arpa/inet.h>
int main()
{
	int sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if(-1 == sockfd)
	{
		perror("socket");
		return -1;
	}
	
	struct sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_port   = htons(6666);
	addr.sin_addr.s_addr = inet_addr("127.0.0.1");

	if(-1 == connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)))
	{
		perror("connect");
		return -1;
	}

	while(1)
	{
		int n;
		printf("input 0 login 1 register\n");
		scanf("%d", &n);

		if(0 == n)
		{
			char buf[20] = "login";
			char name[100];
			char passwd[100];
			write(sockfd, buf, sizeof(buf));
			
			printf("input name->");
			scanf("%s", name);
			printf("input passwd->");
			scanf("%s", passwd);
			write(sockfd, name, sizeof(buf));
			write(sockfd, passwd, sizeof(passwd));
			read(sockfd, buf, sizeof(buf));
			printf("result is %s\n", buf);
		}
		else
		{
			char buf[20] = "register";
			char name[100];
			char passwd[100];
			write(sockfd, buf, sizeof(buf));
			
			printf("input name->");
			scanf("%s", name);
			printf("input passwd->");
			scanf("%s", passwd);
			write(sockfd, name, sizeof(buf));
			write(sockfd, passwd, sizeof(passwd));
			read(sockfd, buf, sizeof(buf));
			printf("result is %s\n", buf);
			
		}

	}

}
